
package methods.Bank;

import java.util.ArrayList;
import java.util.Arrays;
import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Condition;
import org.powerbot.concurrent.strategy.Strategy;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;

/**
 *
 * @author CmptrPrgmr
 */
public class CP3BankPin extends Strategy implements Condition, Task
{

	private int[] bankPin = new int[4];
	private int WIDGET_BANK_PIN = 13;
	private int WIDGET_CHILD_BANK_PIN_WINDOW = 0;
	private int WIDGET_CHILD_BANK_PIN_INDEX = 28;
	private int WIDGET_CHILD_EXIT = 25;

	private int[] PIN_BUTTONS = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
	private String[] alphaStates = {"FIRST", "SECOND", "THIRD", "FOURTH"};
	ArrayList<String> states = new ArrayList<String>(Arrays.asList(alphaStates));
	
	@Override
	public boolean validate() {
		return Widgets.get(WIDGET_BANK_PIN, WIDGET_CHILD_BANK_PIN_WINDOW).validate();
	}

	@Override
	public void run() {
		switch (getState(Widgets.get(WIDGET_BANK_PIN, WIDGET_CHILD_BANK_PIN_INDEX).getText()))
		{
			case 0:
				if (Widgets.get(WIDGET_BANK_PIN, this.PIN_BUTTONS[this.bankPin[0]]).click(true))
				{
					Time.sleep(Random.nextInt(317, 579));
					break;
				}
			case 1:
				if (Widgets.get(WIDGET_BANK_PIN, this.PIN_BUTTONS[this.bankPin[1]]).click(true))
				{
					Time.sleep(Random.nextInt(289, 529));
					break;
				}
			case 2:
				if (Widgets.get(WIDGET_BANK_PIN, this.PIN_BUTTONS[this.bankPin[2]]).click(true))
				{
					Time.sleep(Random.nextInt(325, 480));
					break;
				}
			case 3:
				if (Widgets.get(WIDGET_BANK_PIN, this.PIN_BUTTONS[this.bankPin[3]]).click(true))
				{
					Time.sleep(Random.nextInt(307, 502));
					break;
				}
		}
				
	}
	
	private int getState(String str)
	{
		for (String state : this.states)
			if (str.contains(state)) return states.indexOf(state);
		return 0;
	}
	
	private CP3BankPin(int[] bankPin)
	{
		int index = 0;
		for (int i : bankPin)
		{
			this.bankPin[index] = i;
			index++;
		}
	}
	
}

